﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace 继承及虚函数调用
{
    public partial class Form1 : Form
    {
        
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            CSonClass csc = new CSonClass();
            csc.CallShow("您好!");

            //下面的转换方法，是利用了类的多态性
            CBaseClass cbc = new CBaseClass();
            cbc = (CBaseClass)csc;
            cbc.CallShow("您好!");//结果调用了子类的方法
        }

        private void button2_Click(object sender, EventArgs e)
        {
            CBaseClass cbc = new CBaseClass();
            cbc.CallShow("您好!");
            
            //下面是错误的转换方法
            //CSonClass csc = (CSonClass)cbc;
            //csc.CallShow("您好!");
        }
    }
}
